package homework;

import org.junit.Test;

import java.util.Arrays;
import java.util.Scanner;


public class Diffcult {
@Test
    public void test01(){
        Scanner sc = new Scanner(System.in);
    int[]arr=new int[5];
    int count=0;
        while(true){
            int n=sc.nextInt();
            if(n==0){
                break;
            }
            if(count>=arr.length){
                int[] temp=new int[arr.length*2];
                System.arraycopy(arr,0,temp,0,arr.length);
                arr=temp;
            }
            arr[count]=n;
            count++;
        }
        System.out.println("有效数据个数:"+count);
        int[] result =new int[count];
        System.arraycopy(arr,0,result,0,count);
        System.out.println(Arrays.toString(result));
    int sum = arraysum(result);
    System.out.println("输入的总和为"+sum);
    }
    int arraysum(int[] result) {
        int sum = 0;
        for (int i = 0; i < result.length; i++) {
            sum += result[i];
        }
        return sum;
    }
}
